/**
 * @file Socket.cc
 * @author zziywang (zziywang@163.com)
 * @brief { life is too short to learn cpp! }
 * @version 1.0
 * @date 2022-05-07
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "Socket.hh"
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

namespace snow
{

Socket::Socket()
{
    fd_ = ::socket(AF_INET, SOCK_STREAM, 0);
    if (-1 == fd_) {
        perror("socket");
    }
}
Socket::Socket(int fd) : fd_(fd) {}
Socket::~Socket()
{
    ::close(fd_);
}

// TCP全双工，主动关闭写端，并不释放
void Socket::shutdownWrite()
{
    ::shutdown(fd_, SHUT_WR);
}

int Socket::getFd() const
{
    return fd_;
}

} // namespace snow